<template>
	<div class="system-role-container layout-padding">
		<div class="system-role-padding layout-padding-auto">
			<el-card shadow="hover" class="pageQueryBoxArea mb10">
				<el-form :model="state.param" :inline="true">
					<el-form-item label="变动类型：">
						<el-select v-model="state.param.changeType" placeholder="请选择变动类型">
							<el-option v-for="item in state.query.changeType" :key="item.value" :label="item.label"
								:value="item.value" />
						</el-select>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="search()">
							<el-icon>
								<ele-Search />
							</el-icon> 搜 索
						</el-button>
					</el-form-item>
				</el-form>
			</el-card>
			<el-card shadow="hover" style="display: flex;flex-direction: column;flex: 1;height: inherit;">
				<section style="display: flex;flex-direction: column; flex: 1;height: inherit;">
					<el-table :data="state.tableData" ref="goodTableRef" row-key="id" style="width: 100%"> 
						<el-table-column label="ID" width="80" align="center">
							<template #default="scope">
								<span>{{ scope.row.id }}</span>
							</template>
						</el-table-column>
						<el-table-column label="佣金变动" align="center">
							<template #default="scope">
								<span>{{ scope.row.name }}</span>
							</template>
						</el-table-column>
						<el-table-column label="变动信息" align="center">
							<template #default="scope">
								<span>￥{{ scope.row.minLowPrice }} ~ {{ scope.row.maxLowPrice }}元</span>
							</template>
						</el-table-column>
						<el-table-column label="变动类型" align="center">
							<template #default="scope">
								<span>{{ scope.row.source }}</span>
							</template>
						</el-table-column>
						<el-table-column label="用户信息" align="center">
							<template #default="scope">
								<el-switch v-model="scope.row.onShelf" />
							</template>
						</el-table-column>
						<el-table-column label="时间" align="center">
							<template #default="scope">
								<span>
									{{ scope.row.salesPolicy == 0 ? '销售' : scope.row.salesPolicy == 1 ? '内采' : '销售/内采' }}
								</span>
							</template>
						</el-table-column>
						<el-table-column label="销售渠道" align="center">
							<template #default="scope">
								<span> {{ scope.row.onShop ? scope.row.onNode ? '线上/门店' : '线上' : '门店' }} </span>
							</template>
						</el-table-column>
						<el-table-column label="操作" align="center">
							<template #default="scope">
								<el-button  text type="primary">
									更多
								</el-button>
							</template>
						</el-table-column>
					</el-table>
					<el-row justify="end">
						<el-col :span="24" class="flex-end-center">
							<el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange" class="mt15"
								:pager-count="5" :page-sizes="[10, 20, 30]" v-model:current-page="state.param.pageNum" background
								v-model:page-size="state.param.pageSize" layout="total, sizes, prev, pager, next, jumper"
								:total="state.total">
							</el-pagination>
						</el-col>
					</el-row>
				</section>
			</el-card>
		</div>
	</div>
</template>

<script setup lang="ts" name="saleIndex">
import { reactive, onMounted, ref, defineAsyncComponent } from 'vue';
import { getBrokerage } from '/@/api/finance';
import { ElMessageBox, ElMessage, TabsPaneContext } from 'element-plus';

// 引入组件
// 定义变量内容

const goodTableRef = ref();
const state = reactive({
	param: {
		showType: 1,
		pageNum: 1,
		pageSize: 10,
	},
	loading: false,
	total: 0,
	tableData: [{}],
	query: {
		changeType: [
			{ label: '全部', value: 1 },
			{ label: '订单返佣', value: 2 },
			{ label: '提现申请', value: 3 },
			{ label: '提现退回', value: 4 },
			{ label: '提现成功', value: 5 },
			{ label: '佣金转余额', value: 5 },
		]
	}
});

// 搜索
const search = () => {
	state.param.pageNum = 1;
	getList();
}

// 获取商品列表
const getList = async () => {
	state.loading = true;//不用传参， 请求得入参在上面都定义了 param这里吗？
	let params = {
		pageNum: state.param.pageNum,
		pageSize: state.param.pageSize,
	}

	const { results } = await getBrokerage(params);
	state.loading = false;
	results.records.map
	state.tableData = results.records.map((obj: any) => ({
		...obj,
		isExpand: false,
		isShowSkuList: false,
	}));
	state.total = results.total;
}

// 分页点击 条数
const onHandleSizeChange = (val: number) => {
	state.param.pageSize = val;
	getList();
};

// 分页点击
const onHandleCurrentChange = (val: number) => {
	state.param.pageNum = val;
	getList();
};

onMounted(() => {
	// 获取商品列表
	getList();
})
</script>
<style scoped lang="scss">
@import '../../../theme/mixins/index.scss';
:deep(.el-card__body){
	display: flex;
	flex-direction: column;
	flex: 1;
	height: inherit;
	.el-table{
		flex: 1;
		.el-table__inner-wrapper::before{
			background: none !important;
		}
	}
}
</style>